Skip to main content

useMeasurement

The useMeasurement hook provides access to the state of the Measurement widget. It allows dynamic configuration of objects in the scene and is part of the @promaton/scan-viewer package.

Interface: MeasurementState

The MeasurementState interface defines the structure and properties available when using the useMeasurement hook.

Properties

allowTogglingMeasureMode

  • Type: boolean
  • Description: Determines whether the UI allows the user to toggle the active measureMode.

interactionState

  • Type: MeasureInteractionState
  • Description: Represents the current state of the measurement tool's interaction.

lastMeasureId

  • Type: string
  • Description: The ID of the most recently added measurement.

measurements

  • Type: object
  • Description: A map containing individual measurements, indexed by their IDs.
  • Index Signature: [id: string]: Measurement

measureMode

  • Type: MeasureMode
  • Description: Indicates the current mode of the measurement tool.

Methods

deleteMeasurement(id)

  • Description: Deletes a specific measurement.
  • Parameters:
    • id (string): The ID of the measurement to delete.
  • Returns: void

update(state)

  • Description: Updates the measurement store with new state values.
  • Parameters:
    • state (Partial<MeasurementState>): The partial state to update.
  • Returns: void

updateMeasurement(id, measurement)

  • Description: Updates a specific measurement.
  • Parameters:
    • id (string): The ID of the measurement to update.
    • measurement (Measurement): The updated measurement object.
  • Returns: void

Example Usage

import { useMeasurement } from "@promaton/scan-viewer";

const {
allowTogglingMeasureMode,
deleteMeasurement,
interactionState,
lastMeasureId,
measurements,
measureMode,
update,
updateMeasurement,
} = useMeasurement();

// Example: Delete a measurement
deleteMeasurement("measurement-id");

// Example: Update the measurement state
update({ allowTogglingMeasureMode: true });

// Example: Update a specific measurement
updateMeasurement("measurement-id", { length: 42 });

The useMeasurement hook is a powerful tool for managing and interacting with measurements in your application. It provides a flexible API to handle dynamic updates and user interactions.